var s94_rem = (function(global){
    let document = global?.document;
    if (!document) return console.error('缺少 document 对象！');
    let rem = {
        valueOf(){
            let fontSize = global.getComputedStyle(document.documentElement)['font-size'];
            return parseFloat(fontSize);
        },
        setScale(scale){
            let is_pc = !/Android|iPhone|iPad/i.test(global.navigator.userAgent);
            scale = scale || (is_pc ? 1 : 1/global.devicePixelRatio);
            let metas = document.querySelectorAll('meta[name="viewport"]');
            let viewport = metas.length ? metas[metas.length-1] : document.createElement('meta');
            if(viewport.name != 'viewport'){
                viewport.name = 'viewport';
                viewport.content = 'width=device-width,user-scalable=no';
                document.querySelector('head').appendChild(viewport);
            }
            let content = `,initial-scale=${scale},minimum-scale=${scale},maximum-scale=${scale}`;
            viewport.content = viewport.content.replace(/,\s*(initial|minimum|maximum)-scale=[^,]+/g,'') + content;
            return this;
        },
        get(base, em){
            var scale = this.scale;
            base = (base || 640) / scale;
            em = (em || 100) / scale;
            var minWH = Math.min(document.documentElement.clientWidth, document.documentElement.clientHeight);
            return em * ((minWH > base ? base : minWH) / base);
        },
        display(base, em){
            var v = this.get(base, em);
            document.documentElement.style.fontSize = v+'px';
            return this;
        }
    }
    Object.defineProperty(rem, 'scale', {
        get(){
            let is_pc = !/Android|iPhone|iPad/i.test(global.navigator.userAgent);
            return is_pc ? 1 : global.outerWidth / global.innerWidth;
        }
    })
    return rem;
})(typeof globalThis !== 'undefined' ? globalThis :
    typeof self !== "undefined" ? self :
        typeof window !== "undefined" ? window :
            typeof global !== "undefined" ? global : {})

export default s94_rem;